/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * recipeView.java
 *
 * Created on Jan 30, 2012, 2:38:46 PM
 */
package laboration2.gui;

import java.util.List;
import se.chalmers.ait.dat215.lab2.Ingredient;
import se.chalmers.ait.dat215.lab2.Recipe;

/**
 *
 * @author arildm
 */
public class RecipeViewOld extends javax.swing.JPanel {

    /** Creates new form recipeView */
    public RecipeViewOld() {
        initComponents();
    }
    
    public void setRecipe(Recipe recipe) {
        nameLabel.setText(recipe.getName());
        imageLabel.setText(null);
        imageLabel.setIcon(recipe.getImage());
        ingredientsLabel.setText(ingrListToText(recipe.getIngredients()));
        descriptionLabel.setText(recipe.getDescription());
        // osv
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameLabel = new javax.swing.JLabel();
        ingredientsLabel = new javax.swing.JLabel();
        descriptionLabel = new javax.swing.JLabel();
        imageLabel = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(laboration2.Laboration2App.class).getContext().getResourceMap(RecipeViewOld.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        nameLabel.setFont(nameLabel.getFont().deriveFont(nameLabel.getFont().getStyle() | java.awt.Font.BOLD, nameLabel.getFont().getSize()+3));
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N

        ingredientsLabel.setText(resourceMap.getString("ingredientsLabel.text")); // NOI18N
        ingredientsLabel.setName("ingredientsLabel"); // NOI18N

        descriptionLabel.setText(resourceMap.getString("descriptionLabel.text")); // NOI18N
        descriptionLabel.setName("descriptionLabel"); // NOI18N

        imageLabel.setText(resourceMap.getString("imageLabel.text")); // NOI18N
        imageLabel.setName("imageLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                        .addComponent(imageLabel))
                    .addComponent(ingredientsLabel)
                    .addComponent(descriptionLabel))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imageLabel)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ingredientsLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(descriptionLabel)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JLabel imageLabel;
    private javax.swing.JLabel ingredientsLabel;
    private javax.swing.JLabel nameLabel;
    // End of variables declaration//GEN-END:variables

    /**
     * Format a list of ingredients as a string.
     * @return A string in the form "amount unit name\namount unit name\n..."
     */
    private String ingrListToText(List<Ingredient> ingredients) {
        // Empty list?
        if (ingredients == null) return null;
        
        StringBuilder builder = new StringBuilder();
        int count = 1;
        for (Ingredient ingr : ingredients) {
            builder.append(ingr.getAmount()).append(" ");
            builder.append(ingr.getUnit()).append(" ");
            builder.append(ingr.getName());
            if (count != ingredients.size()) {
                builder.append("\n");
                count++;
            }
        }
        return builder.toString();
    }
}
